﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace TST.SharePointObjects
{
    public class RowSelectColumn : ITemplate
    {
        public RowSelectColumn()
        {
        }

        public void InstantiateIn(Control container)
        {
            if (container != null)
            {
                RadioButton select = new RadioButton();
                select.EnableViewState = false;
                select.DataBinding += new EventHandler(select_DataBinding);
                container.Controls.Add(select);
            }
        }

        private void select_DataBinding(object sender, EventArgs e)
        {
            RadioButton select = (RadioButton)sender;
            GridViewRow row = (GridViewRow)select.NamingContainer;
            GridView grid = (GridView)row.NamingContainer;
            string id = row.RowIndex.ToString();
            select.Attributes.Add("onClick", string.Format("javascript:{0}", grid.Page.ClientScript.GetPostBackEventReference(grid, string.Format("Select${0}", id, true))));
            select.Checked = grid.SelectedIndex == row.RowIndex;
        }
    }
}
